package com.tomowork.service.impl;

import com.tomowork.dao.IEmpDAO;
import com.tomowork.entity.Dept;
import com.tomowork.entity.Emp;
import com.tomowork.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.Date;
import java.util.List;
import java.util.Random;

@Service("iEmpService")
@Transactional
public class EmpServiceImpl implements IEmpService {
    @Autowired
    private IEmpDAO empDAO;

    @Override
    @Transactional
    public void insert(Emp emp,Integer deptno) {
        Dept dept = new Dept() ;
        dept.setDeptno(deptno);
        emp.setUpdatetime(new Date());
        emp.setCreatetime(new Date());
        emp.setDept(dept);
        empDAO.doCreate(emp) ;
    }

    @Override
    public boolean update(Emp emp) {
        return empDAO.doUpdate(emp);
    }

    @Override
    public boolean delete(Integer empno) {
        return empDAO.doRemove(empno);
    }

    @Override
    public Emp selectByEmpno(Integer empno) {
        return empDAO.findByEmpno(empno);
    }

    @Override
    public List<Emp> selectAll(int pageNum,int pageSize) {
         return empDAO.findAll(pageNum,pageSize);
    }

    @Override
    @Transactional
    public void BatchSave(List<Emp> emps) {
        empDAO.BatchSave(emps) ;
    }

    @Override
    public int getAllCount() {
        return empDAO.getAllCount();
    }
}

